In certain conditions, it is difficult to capture image keeping the entire subject in focus. For instance, photos of innards in endoscopy may comprise regions located at substantially different distances from the camera lens and exceeding the focal depth of the image capture device. As a result, at least one region in the obtained images will be out of focus.
Focus stacking is a tool allowing to extend the depth of field of a digital image. This technique is based on merging multiple source images of the same scene captured, as a rule, from the same viewpoint and with different position of depth of field (for instance, a set of static images taken from a fixed viewpoint, or a series of frames from a fixed video camera) in order to produce an output image with the depth of field larger than on each individual image. That is to say that individual source images being merged provide the necessary data for creation of a composite output image with more or all of the parts of the subject in focus. Focus stacking may be used in different cases when individual images have relatively shallow depth of field, for instance, in macro photography, optical microscopy, landscape photography etc.
There are several ways to perform focus stacking, one of them is the method based on generation of a depth map. In their turn, known methods of performing focus stacking based on depth map use different techniques for detecting depth of field and improving quality of the depth map based thereon. But efficiency of these methods is often low, the methods themselves being controversial due to their high computational complexity. For instance, the patent claim WO2014083574 describes focus stacking technique based on the depth map that is in its turn created on the basis of an energy matrix. In order to produce a better result, the depth map is modified in the zones corresponding to low contrast regions with noise, using fixed focus measure value (cutoff threshold) for determining low contrast regions for their further cutoff. But implementation of the above mentioned technique causes visual artifacts in the output image, and said fixed value is to be preliminarily determined and adjusted.